package com.lemon.smartsafetynew.ui.adapter.contact;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.contact.DepartmentVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/9/11.
 */

public class DepartmentListAdapter extends LemonRcvAdapter<DepartmentVo> {

    private RecyclerTClickListener<DepartmentVo> mListener;

    public DepartmentListAdapter(@Nullable List<DepartmentVo> data,
                                 RecyclerTClickListener<DepartmentVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<DepartmentVo> {

        private DepartmentVo mData;
        private int mPosition;

        @Bind(R.id.name_tv)
        TextView nameTv;
        @Bind(R.id.common_choose_item_layout)
        LinearLayout commonChooseItemLayout;

        @Override
        public int getLayoutResId() {
            return R.layout.item_common_choose;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            commonChooseItemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(mData, mPosition);
                }
            });
        }

        @Override
        public void handleData(DepartmentVo departmentVo, int position) {

            mPosition = position;
            mData = departmentVo;

            nameTv.setText(CommonUtil.avoidNullString(departmentVo.getName()));

        }
    }
}
